/**
 * dialog - jQuery xui
 *
 * Licensed under the GPL:
 *   http://www.gnu.org/licenses/gpl.txt
 *
 * Copyright 2013 xjb [ beymy.en@gmail.com ]
 *
 */
(function($) {

    $.fn.dialog = function(options, param) {
        if (typeof options == 'string') {
            return $.fn.dialog.methods[options](this, param);
        }

        options = options || {};
        return this.each(function() {
            var state = $.data(this, 'dialog');
            if (state) {
                $.extend(state.options, options);
            } else {
                state = $.data(this, 'dialog', {
                    options: $.extend({}, $.fn.dialog.defaults, $.fn.dialog.parseOptions(this), options)
                });
                if (!state.options.inline) {
                    document.body.appendChild(this);
                }
            }
            bindEvents(this);
        });
    };

    $.fn.dialog.methods = {
        options: function(jq) {
            return $.data(jq[0], 'dialog').options;
        }
    };

    $.fn.dialog.parseOptions = function(target) {
        return $.extend({}, $.parser.parseOptions(target));
    };

    $.fn.dialog.defaults = {};
})(jQuery);